package com.limi.gridfsop.controller;

import com.limi.gridfsop.domain.BizFile;
import com.limi.gridfsop.service.FileService;
import com.limi.gridfsop.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;

/**
 * @author limi
 * @date 2020/04/27
 */
@RestController
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public Result uploadFile(@PathVariable("file") MultipartFile file) {
        BizFile bizFile = new BizFile();
        bizFile.setUrl("/gridop/downloadFile/"+fileService.storeFile(file));
        return Result.success(bizFile);
    }

    @GetMapping("/download")
    public void download(@RequestParam("id") String id) {
        //fileService.getFile(id);
    }

    @GetMapping("/downloadFile/{id}")
    public void downloadFile(@PathVariable("id") String id) {
        fileService.downloadFile(id);
    }
}
